<?php

namespace Apipad\Controller;
//设计师中心
header("content-type:application/json;charset=utf-8");
class DescignController extends ComController{

    public function get_cate(){
        $design_cate_model = M('imgcate');
        $map['is_delete'] = 0;
        $map['status'] = 12;
        $list = $design_cate_model->where($map)->order('id asc')->field('id,title')->select();
        $data['code'] = 200;
        $data['msg'] = '查询成功';
        $data['data']['list'] = $list;
        exit(json_encode($data));
    }
    public function get_brand_cate(){
        $mianliao_cate = M('mianliao_cate');
        $map['isdel'] = 0;
        $map['uid']=UID;
        $wap['isdel'] = 0;
        $wap['uid'] = 0;
        $list = $mianliao_cate->where($map)->order('id asc')->field('id,title')->select();
        if(empty($list)){
            $list = $mianliao_cate->where($wap)->order('id asc')->field('id,title')->select();
        }
        $data['code'] = 200;
        $data['msg'] = '查询成功';
        $data['data']['list'] = $list;
        exit(json_encode($data));
    }
    public function get_desig_list(){
        $detail = I('post.');
        $page=$detail['page']?$detail['page']:1;
        $limit=$detail['limit']?$detail['limit']:12;
        $cate_id=$detail['cate_id']?$detail['cate_id']:0;
        $design_model = M('gongyitu');
        $map = [];
        $map['is_delete'] = 0;
        $map['cate_id'] = $cate_id;
        $count = $design_model->where($map)->count();
        $list = $design_model->where($map)->order('id asc')->page($page,$limit)->field('id,title,pic,imgc as pict')->select();
        $data['code'] = 200;
        $data['msg'] = '查询成功';
        $data['data']['count'] = $count;
        $data['data']['list'] = $list;
        exit(json_encode($data));
    }
    public function get_designlist(){
        $detail = I('post.');
        $page=$detail['page']?$detail['page']:1;
        $limit=$detail['limit']?$detail['limit']:12;
        $page=$detail['page']?$detail['page']:1;
        $cate_id=$detail['cate_id']?$detail['cate_id']:0;
        $mianliao = M('mianliao');
        $map = [];
        $map['isdel'] = 0;
        $map['uid']=UID;
        if($cate_id){
            $map['cate_id']=$cate_id;
        }
        $count =$mianliao->where($map)->count();
        if($count==0){
            $wap['isdel'] = 0;
            if(empty($cate_id)){
                $cate_id=1;
            }
            $wap['cate_id'] = $cate_id;
            $wap['uid'] = 0;
            $count = $mianliao->where($wap)->count();
            $list = $mianliao->where($wap)->order('id asc')->page($page,$limit)->field('goods_id as id,mianliao_name,suppler_price,mianliao_pic')->select();
        }else {
            $list = $mianliao->where($map)->order('id asc')->page($page,$limit)->field('goods_id as id,mianliao_name,suppler_price,mianliao_pic')->select();
        }
        $data['code'] = 200;
        $data['msg'] = '查询成功';
        $data['data']['count'] = $count;
        $data['data']['list'] = $list;
        exit(json_encode($data));
    }
    //
    public function add_designc(){
        $detail = I('post.');
        $mianliao_name=$detail['mianliao_name']?$detail['mianliao_name']:'标题111';
        $suppler_price=mt_rand(1, 2000);  
        $mianliao_pic=$detail['mianliao_pic']?$detail['mianliao_pic']:'';
        $cate_id=$detail['cate_id']?$detail['cate_id']:1;
        if(empty($mianliao_pic)){
            $data['code'] = 0;
            $data['msg'] = '请上传图片';
            exit(json_encode($data));
        }
        $mianliao = M('mianliao');
        $attr_data['mianliao_name']=$mianliao_name;
        $attr_data['mianliao_pic']=$mianliao_pic;
        $attr_data['suppler_price']=$suppler_price;
        $attr_data['cate_id']=$cate_id;
        $attr_data['isdel']=0;
        $mianliao->startTrans();
        $result=$mianliao->add($attr_data);
        if($result){
            $mianliao->commit();
            $data_cc['code'] = 200;
            $data_cc['msg'] = "添加成功";
            $data_cc['data'] = $result;
            exit(json_encode($data_cc));
        } else {
            $data_cc['code'] = 0;
            $data_cc['msg'] = "添加失败";
            exit(json_encode($data_cc));
        }
    }
 
}
